package com.ymatou.iapi.livebuyer.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.IsLiveCanReplayBean;
import com.ymatou.iapi.livebuyer.service.IsLiveCanReplayCall;
import com.ymatou.livevideo.parameter.RecLiveNotifyBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.YMTDateUtil;

/**
 * 查询直播是否可以回放 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_IsLiveCanReplay {
	private static IsLiveCanReplayBean islivecanreplayBean;
	private static IsLiveCanReplayCall islivecanreplayCall;
	private static LiveRoomWapper liveRoomWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询直播是否可以回放");
	}

	@Before
	public void caseUp() {
		islivecanreplayBean = new IsLiveCanReplayBean();
		islivecanreplayCall = new IsLiveCanReplayCall();
		liveRoomWapper = new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(islivecanreplayCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_IsLiveCanReplay_001() {
		Logger.start(true, "状态7有replay字段查询直播可以回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));

			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(createlive.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 7);
			Thread.sleep(1100);
			islivecanreplayBean.setLiveId(createlive.getId());
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("200", islivecanreplayCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(true, islivecanreplayCall.getJsonObject().get("data").getAsJsonObject().get("isLiveCanReplay").getAsBoolean(), "验证isLiveCanReplay");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_IsLiveCanReplay_002() {
		Logger.start(true, "查询直播不可以回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			islivecanreplayBean.setLiveId(createlive.getId());
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("200", islivecanreplayCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(false, islivecanreplayCall.getJsonObject().get("data").getAsJsonObject().get("isLiveCanReplay").getAsBoolean(), "验证isLiveCanReplay");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_IsLiveCanReplay_003() {
		Logger.start(true, "不输入liveid失败");
		try {
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("100", islivecanreplayCall.getString("code"), "判断code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_IsLiveCanReplay_004() {
		Logger.start(true, "状态8有replay字段查询直播可以回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));

			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(createlive.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 8);
			Thread.sleep(1100);
			islivecanreplayBean.setLiveId(createlive.getId());
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("200", islivecanreplayCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(true, islivecanreplayCall.getJsonObject().get("data").getAsJsonObject().get("isLiveCanReplay").getAsBoolean(), "验证isLiveCanReplay");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_IsLiveCanReplay_005() {
		Logger.start(true, "状态9有replay字段查询直播可以回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));

			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(createlive.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 9);
			Thread.sleep(1100);
			islivecanreplayBean.setLiveId(createlive.getId());
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("200", islivecanreplayCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(true, islivecanreplayCall.getJsonObject().get("data").getAsJsonObject().get("isLiveCanReplay").getAsBoolean(), "验证isLiveCanReplay");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_IsLiveCanReplay_006() {
		Logger.start(true, "状态10有replay字段查询直播不可以回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));

			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(createlive.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 10);
			Thread.sleep(1100);
			islivecanreplayBean.setLiveId(createlive.getId());
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("200", islivecanreplayCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(false, islivecanreplayCall.getJsonObject().get("data").getAsJsonObject().get("isLiveCanReplay").getAsBoolean(), "验证isLiveCanReplay");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_IsLiveCanReplay_007() {
		Logger.start(true, "状态7无replay字段查询直播不可以回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 7);
			Thread.sleep(1100);
			islivecanreplayBean.setLiveId(createlive.getId());
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("200", islivecanreplayCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(false, islivecanreplayCall.getJsonObject().get("data").getAsJsonObject().get("isLiveCanReplay").getAsBoolean(), "验证isLiveCanReplay");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_IsLiveCanReplay_008() {
		Logger.start(true, "状态8无replay字段查询直播不可以回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 8);
			Thread.sleep(1100);
			islivecanreplayBean.setLiveId(createlive.getId());
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("200", islivecanreplayCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(false, islivecanreplayCall.getJsonObject().get("data").getAsJsonObject().get("isLiveCanReplay").getAsBoolean(), "验证isLiveCanReplay");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_IsLiveCanReplay_009() {
		Logger.start(true, "状态9无replay字段查询直播不可以回放成功");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 9);
			Thread.sleep(1100);
			islivecanreplayBean.setLiveId(createlive.getId());
			islivecanreplayCall.setData(islivecanreplayBean);
			islivecanreplayCall.callService();
			Logger.verifyEquals("200", islivecanreplayCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(false, islivecanreplayCall.getJsonObject().get("data").getAsJsonObject().get("isLiveCanReplay").getAsBoolean(), "验证isLiveCanReplay");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}